import pygame

from CTextureManager import CTextureManager
from CSoundManager import CSoundManager

class CWeapon(object):
    """ Holds weapon data and visual information """
    

    def __init__(self , name , attackDamage , durability ):
        """ Create a basic weapon binding from a sprite , name and some basic statistics. Weapons are generally just a single sprite that will be attached to the character. """
        if( CTextureManager.IsLoadedTexture( name ) == False ):
            self.mOriginalSprite = CTextureManager.LoadTexture("img/W_" + name + ".gif" , name )
        else:
            self.mOriginalSprite = CTextureManager.GetTexture(name)

        self.mTransformedSprite = pygame.transform.rotate( self.mOriginalSprite , 0 )
        self.mName = name
        self.mAttackDamage = attackDamage
        self.mDurability = durability
        
        # Load Sound
        if( CSoundManager.IsLoadedSound( name ) == False ):
            self.mSound = CSoundManager.LoadSound("audio/W_" + name + ".ogg" , name )
        else:
            self.mSound = CSoundManager.GetSound(name)
        
    def draw(self , inScreen , x , y):
        """ Draw our character. Call this after the level and other background objects have been drawn. """
        inScreen.blit( self.mTransformedSprite, ( x , y ) )
        
    def rotate(self , angle ):
        """ This will rotate our weapon by a given angle. The rotation is done by transforming the original sprite to avoid distortions that come with rotation. """
        self.mTransformedSprite = pygame.transform.rotate( self.mOriginalSprite , angle )  
        
    def playSound(self):
        """ Play the sound associated with this weapon. """
        self.mSound.play()
        
        

        
        
        
         

